package per.songyu.goods.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import per.songyu.goods.pojo.Goods;
import per.songyu.goods.service.GoodsService;


import java.util.List;

@RestController
@RequestMapping("/goods/")

public class GoodsController {

    @Autowired //has a
    private GoodsService goodsService;

    @RequestMapping("doGoodsUI")
    public List<Goods> doGoodsUI(){
        List<Goods> goodsList=goodsService.findGoods();
        return goodsList;
    }

    @RequestMapping("selectById")
    public Goods selectById(int id){
        Goods goodsList=goodsService.findGoodsById(id);
        return goodsList;
    }

    @PostMapping("doGoodsUpdate")
    public int doGoodsUpdate(@RequestBody Goods goods){
        return  goodsService.doUpdateById(goods);
    }

    @RequestMapping("insert")
    public int insert(@RequestBody Goods entity){
        return goodsService.saveGoods(entity);
    }

    @RequestMapping("doDeleteById/{id}")
    public String doDeleteById(@PathVariable Integer id){
        goodsService.doDeleteById(id);
        return "redirect:/goods/doGoodsUI";
    }
}
